import request from '@/utils/request'

/**
 * 创建仪表板
 * @param {Object} data 仪表板数据
 * @returns {Promise}
 */
export function createDashboard(data) {
  return request({
    url: '/api/dashboard/manage/create',
    method: 'post',
    data
  })
}

/**
 * 获取图表选项
 * @returns {Promise}
 */
export function getChartOptions() {
  return request({
    url: '/api/dashboard/manage/chart-options',
    method: 'get'
  })
}

/**
 * 添加图表
 * @param {Number} dashboardId 仪表板ID
 * @param {Object} data 图表数据
 * @returns {Promise}
 */
export function addChart(dashboardId, data) {
  return request({
    url: `/api/dashboard/manage/${dashboardId}/charts`,
    method: 'post',
    data
  })
}

/**
 * 删除图表
 * @param {Number} dashboardId 仪表板ID
 * @param {Number} chartId 图表ID
 * @returns {Promise}
 */
export function deleteChart(dashboardId, chartId) {
  return request({
    url: `/api/dashboard/manage/${dashboardId}/charts/${chartId}`,
    method: 'delete'
  })
}

/**
 * 更新仪表板状态
 * @param {Number} id 仪表板ID
 * @param {String} status 状态
 * @returns {Promise}
 */
export function updateDashboardStatus(id, status) {
  return request({
    url: `/api/dashboard/manage/${id}/status`,
    method: 'put',
    params: { status }
  })
}

/**
 * 获取图表数据
 * @param {String} dataSource 数据源
 * @param {String} chartType 图表类型
 * @param {Object} filters 过滤条件
 * @returns {Promise}
 */
export function getChartData(dataSource, chartType, filters = {}) {
  return request({
    url: '/api/dashboard/chart-data',
    method: 'get',
    params: {
      dataSource,
      chartType,
      ...filters
    }
  })
}

/**
 * 获取仪表板详情
 * @param {String} id 仪表板ID
 * @returns {Promise}
 */
export function getDashboardDetail(id) {
  return request({
    url: `/api/dashboard/manage/detail/${id}`,
    method: 'get'
  })
}